package com.LeetCode.Tree;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 二叉树完全性校验
 */
public class checkTree {
    public boolean isCompleteTree(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        boolean hasNullOnLeft = false;
        while(!queue.isEmpty()){
            TreeNode node = queue.poll();
            if(node == null){
                hasNullOnLeft = true;
            }else{
                if(hasNullOnLeft) return false;
                queue.offer(node.left);
                queue.offer(node.right);
            }
        }
        return true;
    }

    @Test
    public void test(){

    }
}
